import { ref } from 'vue'
import { defineStore } from 'pinia'
import { codeNoteMockData } from './mockData/CodeNote'

export const useCodeNoteStore = defineStore('counter', () => {
  const isLogin = ref(false)

  const login = (value: boolean): Promise<boolean> => { // 模拟接口-登录登出
    return new Promise(resolve => {
      setTimeout(() => {
        isLogin.value = value
        resolve(true)
      }, 200)
    })
  }

  const getCode = (): Promise<Record<string, any>[]> => { // 模拟接口-获取code数据
    return new Promise(resolve => {
      setTimeout(() => {
        resolve(codeNoteMockData.code)
      }, 200)
    })
  }

  const submit = (value: Record<string, any>[]): Promise<boolean> => { // 模拟接口-提交
    return new Promise(resolve => {
      setTimeout(() => {
        const info = value.map((item: Record<string, any>) => {
          return {
            language: item.language,
            code: item.code,
          }
        })
        codeNoteMockData.code = info
        resolve(true)
      }, 200)
    })
  }

  return { isLogin, login, getCode, submit }
})